from flask import Flask, jsonify
from functools import lru_cache

class SquareCalculator:

    @staticmethod
    @lru_cache(maxsize=2)
    def calculate_square(number):
        print("发生了计算")
        return number ** 2

app = Flask(__name__)
calculator = SquareCalculator()

@app.route('/square/<int:number>')
def get_square(number):
    result = calculator.calculate_square(number)
    return jsonify({
        "number": number,
        "square": result
    })

if __name__ == '__main__':
    app.run(debug=True)